package com.probiz.estore.content.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.probiz.estore.common.model.content.Newsletter;
import com.probiz.estore.content.dao.NewsletterDao;
import com.probiz.estore.content.service.NewsletterManager;
import com.probiz.estore.content.service.SubscriberManager;
import com.probiz.estore.core.service.impl.GenericManagerImpl;
import com.probiz.estore.customer.service.CustomerManager;
import com.probiz.estore.system.service.MsgSendManager;
import com.probiz.estore.system.util.MailEngine;
import com.probiz.estore.system.util.MsgTemplateConstants;


/**
 * Manager implementation for Newsletter, responsible for business processing, and communicate between web and persistence layer.
 */
public class NewsletterManagerImpl extends GenericManagerImpl<Newsletter> implements NewsletterManager {
	/** 消息默认模板*/
	private final static String TEMPLATE_PATH = "/newsletter/normal.vm";
	
	private NewsletterDao newsletterDao = null;

	private MsgSendManager msgSendManager = null;
	
	public void setMsgSendManager(MsgSendManager msgSendManager) {
		this.msgSendManager = msgSendManager;
	}

	/**
	 * @param newsletterDao
	 *            the newsletterDao to set
	 */
	public void setNewsletterDao(NewsletterDao newsletterDao) {
		this.newsletterDao = newsletterDao;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#init()
	 */
	@Override
	protected void initManager() {
		dao = newsletterDao;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#preDelete(java.lang.Object)
	 */
	@Override
	protected void preDelete(Newsletter entity) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#preSave(java.lang.Object)
	 */
	@Override
	protected void preSave(Newsletter entity) {

	}
	
	/**
	 * 测试消息发送，主用便于后台管理员测试消息的显示效果
	 * @param newsletter  消息实体
	 * @param recipients	收件人
	 */
	public void testEmailNewletter(Newsletter newsletter, String... recipients){
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("newsletter", newsletter);
		msgSendManager.sendMsg(MsgTemplateConstants.MESSAGE_INFORMATION_TAKE, model, recipients, null, null);
	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.content.service.NewsletterManager#getAllNewslettersToSend(Integer, int, int)
	 */
	public List<Newsletter> getAllNewslettersToSend(Integer storeId, int pageNo1, int pageSize) {
		return newsletterDao.getAllNewslettersToSend(storeId, pageNo1, pageSize);
	}

}
